#ifndef XM_CURTHREAD_HH
#define XM_CURTHREAD_HH

#ifdef __linux__
#include <unistd.h>
#include <sys/syscall.h>
#endif

#include "pch.hh"

XM_NAMESPACE_BEGIN

namespace CurThread
{
extern __thread int t_cachedTid;

void cacheTid();

inline int tid()
{
    if (__builtin_expect(
        t_cachedTid == 0, 0
    )) cacheTid();

    return t_cachedTid;
}

} // namespace XM::CurThread

XM_NAMESPACE_END

#endif // header file protect